import { setLocalData, getLocalData } from "happy-utils/storage";

/**
 * 设置本地存储的值
 * @param {string} key
 * @param {string, obj} value
 */
function setLocal(key, value) {

    if (typeof value === 'object') value = JSON.stringify(value);

    setLocalData(key, value);

    return true;
}

/**
 * 获取本地存储的值
 * @param {string} key
 * @param {boole} parse
 */
function getLocal(key, parse) {

    let get = getLocalData(key);

    if (parse) get = JSON.parse(get);

    return get;
}

/**
 * 删除本地存储的值
 * @param {string} key
 */
function delLocal(key) {
    localStorage.removeItem(key)
}

export default {
    setLocal,
    getLocal,
    delLocal
};